package com.qdxwx.data.service.cash;

import com.qdxwx.common.page.PageRequest;
import com.qdxwx.data.mapper.cash.CashApplyMapper;
import com.qdxwx.models.cash.CashApply;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * Qdx NetSchool Platform
 * @author qdxwx
 * @updateTime 2022/5/25
 * @description
 */
@Service
public class CashApplyServiceImpl implements CashApplyService {

    @Autowired
    private CashApplyMapper cashApplyMapper;

    @Override
    public int insert(CashApply cashApply) {
        cashApply.setCreateTime(LocalDateTime.now());
        return cashApplyMapper.insertCashApply(cashApply);
    }

    @Override
    public int update(CashApply cashApply) {
        if (cashApply.getId() < 1) return 0;
        return cashApplyMapper.updateCashApply(cashApply);
    }

    @Override
    public CashApply get(int id) {
        if (id < 1) return null;
        return cashApplyMapper.selectById(id);
    }

    @Override
    public List<CashApply> getList(CashApply query, PageRequest page) {
        return cashApplyMapper.selectList(query, page);
    }

    @Override
    public int count(CashApply query) {
        return cashApplyMapper.selectCount(query);
    }

    @Override
    public int updateCombine(long userId1, long userId2) {
        if(userId1 < 1 || userId2 < 1){
            throw new RuntimeException("更新用户提现申请：参数错误");
        }
        return cashApplyMapper.updateCombine(userId1, userId2);
    }
}
